#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

#define SIZE 1000000000

double worker_output;
double master_output;

void *worker(void *arg) {
    int i;
    for(i = 1; i < SIZE / 2; i ++) {
        if(i % 2) worker_output += (1.0 / (2 * i - 1));
        else worker_output -= (1.0 / (2 * i - 1));
    }
    return NULL;
}

void master() {
    int i;
    for(i = SIZE / 2; i <= SIZE; i ++) {
        if(i % 2) master_output += (1.0 / (2 * i - 1));
        else master_output -= (1.0 / (2 * i - 1));
    }
}

void main() {
    pthread_t worker_id;
    double sum = 0;

    pthread_create(&worker_id, NULL, worker, NULL);
    master();
    pthread_join(worker_id, NULL);
    sum = worker_output + master_output;
    // printf("%lf %lf\n", worker_output, master_output);
    printf("PI = %.8lf\n", 4 * sum);
}
